package main

import (
	gconfig "funlog-gserver/config"
	router "funlog-gserver/router"
	db "funlog-gserver/stored/db"
	es "funlog-gserver/stored/es"
	nsq "funlog-gserver/stored/nsq"
	nsqs "funlog-gserver/stored/nsq/cunsumer"
	qqwry "funlog-gserver/stored/qqwry"
	redis "funlog-gserver/stored/redis"
	"io"
	"log"

	"github.com/gin-gonic/gin"
)

func main() {
	var writer io.Writer
	// 初始化日志
	gconfig.InitLog(&writer)
	gin.DefaultWriter = io.MultiWriter(writer)
	// log.Println("=====================funlog-gserver start==========================")
	//读取配置
	gconfig.ReadConfig()
	//初始化nsq
	nsq.InitNSQ()
	//初始化缓存数据库
	redis.InitRedis()
	//初始化数据库
	db.InitDB()
	//初始化数据库
	es.InitES()
	//初始化ip解析
	qqwry.InitQQWRY()
	//初始化消费者
	nsqs.InitNQConsumers()
	//启动http监听
	r := gin.Default()
	if gconfig.Cnf["HTTP_MODE"] != "debug" {
		gin.SetMode(gin.ReleaseMode)
	}
	//加载路由
	router.Load(r)
	listenPort := gconfig.Cnf["LISTEN_PORT"]
	log.Println("=====================funlog-gserver listen " + listenPort + "==========================")
	r.Run(":" + listenPort) // 监听listenPort并启动服务
}
